package com.codermn.枚举类;

/**
 * @author jxau_scf
 * @date 2021/7/28 - 16:44
 */
public enum PayEnum implements BaseEnum {
    WAITING_PAY("1", "0", "待支付", "unionpay", "银联"),
    SUCCESS_PAY("2", "1", "支付成功", "unionpay", "银联"),
    FAIL_PAY("3", "2", "支付失败", "unionpay", "银联"),

    ALIPAY_WAITING_PAY("1","3","待支付","alipay","支付宝")
    ;

    private String key;
    private String value;
    private String desc;
    //本类扩展字段 用于对接不同系统的支付状态
    private String channel;
    private String channelDesc;

    PayEnum(String key, String value, String desc, String channel, String channelDesc) {
        this.key = key;
        this.value = value;
        this.desc = desc;
        this.channel = channel;
        this.channelDesc = channelDesc;
    }


    @Override
    public String getKey() {
        return this.key;
    }

    @Override
    public String getValue() {
        return this.value;
    }

    @Override
    public String getDesc() {
        return this.desc;
    }

    public String getChannel(){
        return this.channel;
    }

    public String getChannelDesc(){
        return this.channelDesc;
    }

    /**
     * 根据 key 和 channel 获得枚举实例
     * @param key
     * @param channel
     * @return
     */
    public static PayEnum match(String key, String channel){
        PayEnum[] enums = PayEnum.values();
        for (PayEnum payEnum : enums){
            if (key.equals(payEnum.getKey()) && channel.equals(payEnum.getChannel())){
                return payEnum;
            }
        }
        return null;
    }

}
